package com.cloudwebrtc.receiver;

import com.cloudwebrtc.service.PhoneService;

import android.content.BroadcastReceiver;  
import android.content.Context;  
import android.content.Intent;  
import android.widget.Toast;  
  
public class HeadsetPlugReceiver extends BroadcastReceiver {  
  
    @Override  
    public void onReceive(Context context, Intent intent) { 
            if(intent.hasExtra("state")){  
                if(intent.getIntExtra("state", 0)==0){  
                    Toast.makeText(context, "Headset disconnected !", Toast.LENGTH_LONG).show();
                    if(PhoneService.isready())
                    {
                    	PhoneService.instance().SetHeadsetIsPlug(false);
                    	if(PhoneService.instance().InCalling() && PhoneService.instance().InVideoCalling())
                    	{
                    		PhoneService.instance().SetLoudspeakerStatus(true);
                    	}
                    }
                }  
                else if(intent.getIntExtra("state", 0)==1){  
                    Toast.makeText(context, "Headset connected !", Toast.LENGTH_LONG).show(); 
                    if(PhoneService.isready())
                    {
                    	PhoneService.instance().SetHeadsetIsPlug(true);
                    	if(PhoneService.instance().InCalling())
                     	{
                    		PhoneService.instance().SetLoudspeakerStatus(false);
                     	}
                    }
                }  
            }  
    }  
}  